/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Vistas.java
 *
 * Created on 23-dic-2011, 21:31:09
 */
package AplicacionMVC;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.util.Map;
import javax.swing.JComboBox;
import funciones.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.util.ArrayList;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.ListModel;

/**
 *
 * @author Jesus Ruiz Oliva
 */
public class Vistas extends javax.swing.JPanel {
      
    /** Creates new form Vistas */
    public Vistas() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelPrincipal = new javax.swing.JPanel();
        etiquetaTitulo = new javax.swing.JLabel();
        etiquetaUsuario = new javax.swing.JLabel();
        etiquetaPass = new javax.swing.JLabel();
        pass = new javax.swing.JPasswordField();
        user = new javax.swing.JTextField();
        buttonAceptar = new javax.swing.JButton();
        buttonExit = new javax.swing.JButton();
        smtp = new javax.swing.JTextField();
        port = new javax.swing.JTextField();
        etiquetaSMTP = new javax.swing.JLabel();
        etiquetaPuerto = new javax.swing.JLabel();
        jPanelROJO = new javax.swing.JPanel();
        etiquetaEmailDestino = new javax.swing.JLabel();
        emailDestino = new javax.swing.JTextField();
        jLabelAtencion = new javax.swing.JLabel();
        panelEmail = new javax.swing.JPanel();
        buttonAtras = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        listModelConsola = new DefaultListModel();
        jListConsola = new javax.swing.JList(listModelConsola);
        jLabelConsola = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listModelConsolaError = new DefaultListModel();
        jListConsolaError = new javax.swing.JList(listModelConsolaError);
        jLabelError = new javax.swing.JLabel();

        setLayout(new java.awt.CardLayout());

        etiquetaTitulo.setFont(new java.awt.Font("Times New Roman", 1, 18));
        etiquetaTitulo.setText("Introduzca los datos de su servidor de e-mail");

        etiquetaUsuario.setText("Usuario");

        etiquetaPass.setText("Contraseña");

        pass.setText("zamparo");

        user.setText("miwe08@gmail.com");
        user.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userActionPerformed(evt);
            }
        });

        buttonAceptar.setText("Aceptar");

        buttonExit.setText("Salir");

        smtp.setText("smtp.gmail.com");
        smtp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smtpActionPerformed(evt);
            }
        });

        port.setText("465");
        port.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                portActionPerformed(evt);
            }
        });

        etiquetaSMTP.setText("SMTP");

        etiquetaPuerto.setText("Puerto");

        jPanelROJO.setBackground(new java.awt.Color(255, 51, 51));

        etiquetaEmailDestino.setText("e-mail destino");

        emailDestino.setText("miwe08@gmail.com");
        emailDestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailDestinoActionPerformed(evt);
            }
        });

        jLabelAtencion.setText("ATENCION !! PARA QUE LO PROBEIS Y Q TODOS LOS E-MAIL DE LOS TRATAMIENTOS LLEGUEN A ESTA DIRECCIÓN");

        javax.swing.GroupLayout jPanelROJOLayout = new javax.swing.GroupLayout(jPanelROJO);
        jPanelROJO.setLayout(jPanelROJOLayout);
        jPanelROJOLayout.setHorizontalGroup(
            jPanelROJOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelROJOLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(etiquetaEmailDestino)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                .addComponent(emailDestino, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(256, 256, 256))
            .addGroup(jPanelROJOLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelAtencion, javax.swing.GroupLayout.PREFERRED_SIZE, 568, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelROJOLayout.setVerticalGroup(
            jPanelROJOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelROJOLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabelAtencion, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(jPanelROJOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(emailDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etiquetaEmailDestino))
                .addGap(35, 35, 35))
        );

        javax.swing.GroupLayout panelPrincipalLayout = new javax.swing.GroupLayout(panelPrincipal);
        panelPrincipal.setLayout(panelPrincipalLayout);
        panelPrincipalLayout.setHorizontalGroup(
            panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrincipalLayout.createSequentialGroup()
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPrincipalLayout.createSequentialGroup()
                        .addGap(292, 292, 292)
                        .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(panelPrincipalLayout.createSequentialGroup()
                                    .addGap(64, 64, 64)
                                    .addComponent(etiquetaPass, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPrincipalLayout.createSequentialGroup()
                                    .addGap(82, 82, 82)
                                    .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(etiquetaPuerto)
                                        .addComponent(etiquetaSMTP))
                                    .addGap(75, 75, 75)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPrincipalLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(etiquetaUsuario)
                                .addGap(70, 70, 70)))
                        .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(pass)
                            .addComponent(user, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                            .addComponent(smtp, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                            .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(75, 75, 75))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPrincipalLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelROJO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(91, 91, 91)))
                .addComponent(buttonAceptar)
                .addGap(22, 22, 22)
                .addComponent(buttonExit)
                .addGap(332, 332, 332))
            .addGroup(panelPrincipalLayout.createSequentialGroup()
                .addGap(294, 294, 294)
                .addComponent(etiquetaTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(505, Short.MAX_VALUE))
        );
        panelPrincipalLayout.setVerticalGroup(
            panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrincipalLayout.createSequentialGroup()
                .addGap(228, 228, 228)
                .addComponent(etiquetaTitulo)
                .addGap(68, 68, 68)
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(user, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etiquetaUsuario))
                .addGap(18, 18, 18)
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etiquetaPass))
                .addGap(18, 18, 18)
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(smtp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etiquetaSMTP))
                .addGap(18, 18, 18)
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etiquetaPuerto))
                .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPrincipalLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(buttonAceptar)
                            .addComponent(buttonExit)))
                    .addGroup(panelPrincipalLayout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jPanelROJO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        add(panelPrincipal, "cardPrincipal");

        buttonAtras.setText("Atras");

        jScrollPane1.setViewportView(jListConsola);

        jLabelConsola.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelConsola.setText("Consola");

        jScrollPane2.setViewportView(jListConsolaError);

        jLabelError.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelError.setText("Errores");

        javax.swing.GroupLayout panelEmailLayout = new javax.swing.GroupLayout(panelEmail);
        panelEmail.setLayout(panelEmailLayout);
        panelEmailLayout.setHorizontalGroup(
            panelEmailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelEmailLayout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jLabelConsola)
                .addContainerGap(1082, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelEmailLayout.createSequentialGroup()
                .addContainerGap(1067, Short.MAX_VALUE)
                .addComponent(buttonAtras)
                .addGap(51, 51, 51))
            .addGroup(panelEmailLayout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(panelEmailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelError)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1061, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1061, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(69, Short.MAX_VALUE))
        );
        panelEmailLayout.setVerticalGroup(
            panelEmailLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelEmailLayout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabelConsola)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jLabelError)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonAtras)
                .addGap(33, 33, 33))
        );

        add(panelEmail, "cardEmail");
    }// </editor-fold>//GEN-END:initComponents

    private void userActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_userActionPerformed

    private void smtpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smtpActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_smtpActionPerformed

    private void portActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_portActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_portActionPerformed

    private void emailDestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailDestinoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailDestinoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAceptar;
    private javax.swing.JButton buttonAtras;
    private javax.swing.JButton buttonExit;
    private javax.swing.JTextField emailDestino;
    private javax.swing.JLabel etiquetaEmailDestino;
    private javax.swing.JLabel etiquetaPass;
    private javax.swing.JLabel etiquetaPuerto;
    private javax.swing.JLabel etiquetaSMTP;
    private javax.swing.JLabel etiquetaTitulo;
    private javax.swing.JLabel etiquetaUsuario;
    private javax.swing.JLabel jLabelAtencion;
    private javax.swing.JLabel jLabelConsola;
    private javax.swing.JLabel jLabelError;
    private javax.swing.JList jListConsola;
    private javax.swing.JList jListConsolaError;
    private javax.swing.JPanel jPanelROJO;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel panelEmail;
    private javax.swing.JPanel panelPrincipal;
    private javax.swing.JPasswordField pass;
    private javax.swing.JTextField port;
    private javax.swing.JTextField smtp;
    private javax.swing.JTextField user;
    // End of variables declaration//GEN-END:variables

    private DefaultListModel listModelConsola;
    private DefaultListModel listModelConsolaError;
    
    // Asociacion de ActionListener  a los botones
    public void addButtonListener(ActionListener aLis){
        buttonAceptar.addActionListener(aLis);
        buttonAtras.addActionListener(aLis);
        buttonExit.addActionListener(aLis);
    }
    // Asociacion de MouseAdapter
    public void addMouseListenerConsola(MouseAdapter mouseAdapter){
        jListConsola.addMouseListener(mouseAdapter);
    }
    public void addMouseListenerConsolaError(MouseAdapter mouseAdapter){
        jListConsolaError.addMouseListener(mouseAdapter);
    }
    
    //*************************************************//
    // Metodos asociados al panel principal (Logearse) //
    //*************************************************//
    
    // Devuelve el usuario introducido
    public String getUsuario(){
        return user.getText();
    }
    // Devuelve el pass introducido
    public String getPass(){ 
        String password = new String(pass.getPassword());
        return password;
    }
     // Devuelve el smtp introducido
    public String getSmtp(){
        return smtp.getText();
    }
    // Devuelve el puerto introducido
    public String getPuerto(){ 
        return port.getText();
    }
    // Devuelve el e-mail destino introducido
    public String getEmailDestino(){ 
        return emailDestino.getText();
    }
    public JButton getButtonAceptar(){
        return buttonAceptar;
    }
    public JButton getButtonExit(){
        return buttonExit;
    }
    //*****************************************//
    // Metodos asociados al panel e-mail       //
    //*****************************************//

    public JButton getButtonAtras(){
        return buttonAtras;
    }
    
    // LISTA CONSOLA
    public String getListConsola(){
        return jListConsola.getSelectedValue().toString();
    }
    public JList getJListConsola(){
        return jListConsola;
    }
    public ListModel getListModelConsola(){
        return listModelConsola;
    }
    public void limpiarListModelConsola(){
         listModelConsola.clear();
    }
    public void setListModelConsola(String cadena){
        listModelConsola.addElement(cadena);
    }
     // LISTA CONSOLA ERROR
    public String getListConsolaError(){
        return jListConsolaError.getSelectedValue().toString();
    }
    public JList getJListConsolaError(){
        return jListConsolaError;
    }
    public ListModel getListModelConsolaError(){
        return listModelConsolaError;
    }
    public void limpiarListModelConsolaError(){
         listModelConsolaError.clear();
    }
    public void setListModelConsolaError(String cadena){
        listModelConsolaError.addElement(cadena);
    }

}
